// this is a reference (uniform of type int1) to the texture unit to use to draw this texture 
// (i.e. if only 1 texture assigned use 0) 
uniform sampler2D sceneTexture;
uniform	mat3	weights;
uniform	float	weightSum;

const	float	OFFSET_DELTA = 0.002;

void main() {
	
	vec2		offsetArray[9];
	offsetArray[0] = vec2(-OFFSET_DELTA, -OFFSET_DELTA);
	offsetArray[1] = vec2(0.0, -OFFSET_DELTA);	
	offsetArray[2] = vec2(OFFSET_DELTA, -OFFSET_DELTA);	
	
	offsetArray[3] = vec2(-OFFSET_DELTA, 0.0);
	offsetArray[4] = vec2(0.0, 0.0);	
	offsetArray[5] = vec2(OFFSET_DELTA, 0.0);	
	
	offsetArray[6] = vec2(-OFFSET_DELTA, OFFSET_DELTA);
	offsetArray[7] = vec2(0.0, OFFSET_DELTA);	
	offsetArray[8] = vec2(OFFSET_DELTA, OFFSET_DELTA);	
	
	vec4	sample[9];
	
	for(int i = 0; i < 9; i++) {
		sample[i] = texture2D(sceneTexture, gl_TexCoord[0].st + offsetArray[i]);
	}	
	
	vec4	textureColour = vec4(((sample[0] * weights[0][0]) + 
										(sample[1] * weights[1][0]) +
										(sample[2] * weights[2][0]) +
										(sample[3] * weights[0][1]) + 
										(sample[4] * weights[1][1]) + 
										(sample[5] * weights[2][1]) +
										(sample[6] * weights[0][2]) + 
										(sample[7] * weights[1][2]) + 
										(sample[8] * weights[2][2])) / weightSum);
	
	// assign the fragment colour to this texture colour
	gl_FragColor = vec4(textureColour);
}
